﻿Public Class clsGJBck
    Public Function selectALL() As DataTable
        Dim szSql As String = ""
        szSql &= " select a.* from sf.b_gjb_ck a "
        szSql &= " where a.location in ( "
        szSql &= " select mst_value from sf.t_mst_list "
        szSql &= " WHERE factory_id = ? "
        szSql &= " and mst_type = ? "
        szSql &= " AND param1 = ?  )"

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, "TS", "07", "2")
        If IsNothing(dt) Then
            selectALL = New DataTable
        Else
            selectALL = dt
        End If
    End Function

    Public Function getListALL() As DataTable
        Dim szSql As String = ""
        szSql &= " select * from sf.b_gjb_ck WHERE factory_id = ? "
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, "TS")
        If IsNothing(dt) Then
            getListALL = New DataTable
        Else
            getListALL = dt
        End If
    End Function

    Public Function getListByDlNo(dl_no As String, status As String) As DataTable
        Dim szSql As String = ""
        szSql &= " select a.*,b.* from sf.b_gjb_ck a inner join sf.b_gjb_dl_info b "
        szSql &= " on  a.factory_id = b.factory_id and a.dl_no = b.dl_no"
        szSql &= " WHERE a.factory_id = ? and b.dl_no = ? and a.status = ?"
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, "TS", dl_no, status)
        If IsNothing(dt) Then
            getListByDlNo = New DataTable
        Else
            getListByDlNo = dt
        End If
    End Function

    Public Function intoCK(en As entity_gjb_ck) As Integer
        Dim sql As String = ""
        Dim rtn As Integer = 0
        DBacs.BeginTransaction()
        Try
            sql &= "INSERT INTO sf.b_gjb_ck( factory_id, dl_no, into_num, gjb_type, location, gjb_dl_info_sys_id, material_code, exprie_date, pgd_id, begin_date, status, into_ope, update_time) "
            sql &= "VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, (SELECT CURRENT_TIMESTAMP(6)), ?, ?, (SELECT CURRENT_TIMESTAMP(6)))"
            With en
                rtn = DBacs.ExecuteUpdateSql(sql, -1， .factory_id, .dl_no, .into_num, .gjb_type, .location, .gjb_dl_info_sys_id, .material_code, .exprie_date, .pgd_id, .status, .into_ope)
            End With

            sql = ""
            sql &= "UPDATE sf.b_gjb_dl_info "
            sql &= "SET status = ?, update_time=(SELECT CURRENT_TIMESTAMP(6)) "
            sql &= "WHERE sys_id = ? "
            rtn = DBacs.ExecuteUpdateSql(sql, -1， "1", en.gjb_dl_info_sys_id)

            sql = ""
            sql &= "UPDATE sf.t_mst_list SET param2 = ?, update_time = ? "
            sql &= "WHERE factory_id = ? and mst_type = ? and mst_value = ? AND param1 = ? "
            rtn = DBacs.ExecuteUpdateSql(sql, -1， "1", Now, "TS", "07", en.location, "2")
            DBacs.CommitTransaction()
        Catch ex As Exception
            DBacs.RollbackTransaction()
            rtn = -2
        End Try
        Return rtn
    End Function

    Public Function outCK(_loc As String, _sys_id As Integer, oper As String) As Integer
        Dim sql As String = ""
        Dim rtn As Integer = 0
        DBacs.BeginTransaction()
        Try
            sql &= " UPDATE sf.b_gjb_ck "
            sql &= " SET  end_date = (SELECT CURRENT_TIMESTAMP(6)) , status = ?, out_ope = ? , update_time = (SELECT CURRENT_TIMESTAMP(6)) "
            sql &= " WHERE factory_id = ? and sys_id = ? "
            rtn = DBacs.ExecuteUpdateSql(sql, -1, "1", oper, "TS", _sys_id)

            sql = ""
            sql &= "UPDATE sf.t_mst_list "
            sql &= "SET param2 = ?, update_time=(SELECT CURRENT_TIMESTAMP(6)) "
            sql &= "WHERE factory_id = ? and mst_type = ? and mst_value = ? AND param1 = ? "
            rtn = DBacs.ExecuteUpdateSql(sql, -1， "0", "TS", "07", _loc, "2")
            DBacs.CommitTransaction()
        Catch ex As Exception
            DBacs.RollbackTransaction()
            rtn = -2
        End Try
        Return rtn
    End Function

End Class
